<!--
 * @Author: JiraiyaChen 979526234@qq.com
 * @Date: 2025-06-23 10:59:33
 * @LastEditors: JiraiyaChen 979526234@qq.com
 * @LastEditTime: 2025-07-28 17:30:56
 * @Description: 评委 所有打分详情
-->

<template>
  <ClDialog v-bind="$attrs" :title="getTitle" width="1390px">
    <el-table
      v-if="loaded"
      height="500px"
      :data="tableData"
      :span-method="objectSpanMethod"
      stripe
      border
      tooltip-effect="light"
    >
      <el-table-column label="评审名称" prop="itemName" :width="150" show-overflow-tooltip fixed="left" />
      <el-table-column label="评分点" prop="pointName" min-width="250" show-overflow-tooltip fixed="left" />
      <el-table-column
        v-for="(column, index) in columnList"
        :key="column.id"
        :label="column.supplierName"
        show-overflow-tooltip
        :width="column.supplierName.length * 25"
        min-width="150"
      >
        <template #default="scope">
          {{ scope.row.pointScoreList[index].score }}
        </template>
      </el-table-column>
    </el-table>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="onSure">确定</el-button>
      </span>
    </template>
  </ClDialog>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import { getJudgePointScore } from '@/api/scoring-details-summary'
const onSure = () => {
  emit('atClose')
}
onMounted(() => {
  init()
})
const loaded = ref(false)
const tableData = ref<any[]>([])
const columnList = ref<any[]>([])
const init = async () => {
  try {
    loaded.value = false
    const res: any = await getJudgePointScore({
      judgeId: props.info.judgeId,
      itemIds: props.info.itemIds,
      projectId: useProjectInfoStore().projectInfo.id
    })
    if (res.length > 0 && res[0].pointSummaryList.length > 0) {
      columnList.value = res[0].pointSummaryList[0].pointScoreList
    }
    tableData.value = handleTableData(res)
    loaded.value = true
  } catch (error) {
    console.log('🐷 🐽 init 🐽 error👉👉👉', error)
    loaded.value = true
  }
}
const handleTableData = (res: any) => {
  const tempData: any[] = []
  res.forEach((item: any) => {
    for (let i = 0; i < item.pointSummaryList.length; i++) {
      const point = item.pointSummaryList[i]
      const rowSpan = i === 0 ? item.pointSummaryList.length : 0
      tempData.push({
        pointName: point.pointName,
        itemName: item.itemName,
        pointScoreList: point.pointScoreList,
        rowSpan
      })
    }
  })
  return tempData
}
const objectSpanMethod = ({ row, column, rowIndex, columnIndex }) => {
  if (columnIndex === 0) {
    return {
      rowspan: row.rowSpan,
      colspan: 1
    }
  }
}
const getTitle = computed(() => {
  return props.type
})

interface infoType {
  judgeId: string
  itemIds: string[]
}
const props = defineProps<{ info: infoType; type: string }>()

const emit = defineEmits<{
  (e: 'atClose', str?: string | undefined): void
  (e: 'reFreshTable', str?: string | undefined): void
}>()
</script>

<style scoped lang="scss"></style>
